/**
 * @project_name staff_vehicle
 * @package_name com.ssh.dao
 * @desc TODO
 * @param
 * @author jack
 * @date 2013-4-25
 * @time 上午7:53:35
 */
package com.ssh.dao;

import java.util.List;

import org.hibernate.SessionFactory;

import com.ssh.entity.FcarDriver;

/**
 * @author jack
 *
 */
public class FcarDriverDAOImpl implements FcarDriverDAOI {
	private SessionFactory sessionFactory;

	/*
	 * (non-Javadoc)
	 *
	 * @see com.ssh.dao.FcarDriverDAOI#addFcarDriver(com.ssh.entity.FcarDriver)
	 */
	@Override
	public FcarDriver addFcarDriver(FcarDriver fcarDriver) {
		// TODO Auto-generated method stub
		try {
			sessionFactory.getCurrentSession().save(fcarDriver);
		} catch (Exception e) {
			return null;
		}
		return fcarDriver;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.ssh.dao.FcarDriverDAOI#addFcarDriverList(java.util.List)
	 */
	@Override
	public int addFcarDriverList(List<FcarDriver> fcarDriverList) {
		// TODO Auto-generated method stub
		return 0;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.ssh.dao.FcarDriverDAOI#countById(java.lang.String)
	 */
	@Override
	public int countById(String id) {
		// TODO Auto-generated method stub
		return 0;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * com.ssh.dao.FcarDriverDAOI#deleteByFcarDriver(com.ssh.entity.FcarDriver)
	 */
	@Override
	public int deleteByFcarDriver(FcarDriver fcarDriver) {
		// TODO Auto-generated method stub
		try {
			sessionFactory.getCurrentSession().delete(fcarDriver);
		} catch (Exception e) {
			return 0;
		}
		return 1;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.ssh.dao.FcarDriverDAOI#deleteById(java.lang.String)
	 */
	@Override
	public int deleteById(String id) {
		// TODO Auto-generated method stub
		int num;
		try {
			String hql = "delete FcarDriver as o where o.id=?";
			num = sessionFactory.getCurrentSession().createQuery(hql)
					.setString(0, hql).executeUpdate();
		} catch (Exception e) {
			return 0;
		}
		return num;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * com.ssh.dao.FcarDriverDAOI#deleteFcarDriverList(com.ssh.entity.FcarDriver
	 * )
	 */
	@Override
	public int deleteFcarDriverList(FcarDriver fcarDriver) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * @return the sessionFactory
	 */
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.ssh.dao.FcarDriverDAOI#queryById(java.lang.String)
	 */
	@Override
	public FcarDriver queryById(String id) {
		// TODO Auto-generated method stub
		try {
			String hql = "from FcarDrive as o where o.id=?";
			return (FcarDriver) sessionFactory.getCurrentSession()
					.createQuery(hql).setString(0, id).uniqueResult();
		} catch (Exception e) {
			return null;
		}

	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.ssh.dao.FcarDriverDAOI#queryByParam(java.lang.String)
	 */
	@Override
	public List<FcarDriver> queryByParam(String param) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * @param sessionFactory
	 *            the sessionFactory to set
	 */
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * com.ssh.dao.FcarDriverDAOI#updateByFcarDriver(com.ssh.entity.FcarDriver)
	 */
	@Override
	public FcarDriver updateByFcarDriver(FcarDriver fcarDriver) {
		// TODO Auto-generated method stub
		try {
			sessionFactory.getCurrentSession().save(fcarDriver);
		} catch (Exception e) {
			return null;
		}

		return fcarDriver;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.ssh.dao.FcarDriverDAOI#updateByFcarDriverList(java.util.List)
	 */
	@Override
	public int updateByFcarDriverList(List<FcarDriver> fcarDriver) {
		// TODO Auto-generated method stub
		return 0;
	}

}
